package com.supereye.platform.web.sys.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.supereye.platform.base.BaseDao;
import com.supereye.platform.web.sys.model.SysUser;
import com.supereye.platform.web.sys.model.SysUserAuth;

@Repository
public class SysUserDao extends BaseDao {

	public void addUser(SysUser user) throws Exception {
		sqlSessionTemplate.insert("com.supereye.platform.web.sys.dao.SysUserDao.addSysUser", user);

	}

	public void updateUser(SysUser user) throws Exception {
		sqlSessionTemplate.update("com.supereye.platform.web.sys.dao.SysUserDao.updateSysUser", user);
	}

	public List<SysUser> getUserList(SysUser user) throws Exception {
		return sqlSessionTemplate.selectList("com.supereye.platform.web.sys.dao.SysUserDao.queryUser", user);
	}

	public void deleteUsers(String[] userIds) throws Exception {
		List<Object[]> params = new ArrayList<Object[]>();
		for(String userId:userIds){
			params.add(new String[]{userId});
		}
		jdbcTemplate.batchUpdate("delete from sys_user where id=?", params);
	}

	public List<SysUser> getUserAuthList(int orgId) throws Exception {
		return sqlSessionTemplate.selectList("com.supereye.platform.web.sys.dao.SysUserDao.queryUserAuthList", orgId);
	}

	public void addUserAuth(SysUserAuth auth) throws Exception {
		sqlSessionTemplate.insert("com.supereye.platform.web.sys.dao.SysUserDao.addSysUserAuth", auth);
	}

	public void deleteUserAuth(SysUserAuth auth) throws Exception {
		sqlSessionTemplate.delete("com.supereye.platform.web.sys.dao.SysUserDao.deleteUserAuth", auth);
	}

	public List<SysUser> getUserListNotAuth() throws Exception {
		return sqlSessionTemplate.selectList("com.supereye.platform.web.sys.dao.SysUserDao.queryUserListNotAuth");
	}
	
	public void updatePassword(int id,String newpassword) throws Exception {
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("newpassword", newpassword);
		params.put("id", id);
		sqlSessionTemplate.update("com.supereye.platform.web.sys.dao.SysUserDao.updatepassword",params);
	}
}
